package com.cy.pj.goods.dao;

import com.cy.pj.goods.pojo.Goods;
import org.apache.ibatis.session.SqlSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.sql.Connection;
import java.sql.Statement;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Repository
public class GoodsDaoImpl implements GoodsDao{

    @Autowired
    private SqlSession sqlSession;


    @Override
    public List<Goods> findGoods() {     //在此方法内部使用sqlsession实现与数据库对话onn=sqlSession.getConnection();
        System.out.println("===findGoods===");

        String statement="com.cy.pj.goods.dao.GoodsDao.findGoods";    //namespace+id
        return sqlSession.selectList(statement);
    }

    @Override
    public int deleteById(Integer id) {
        String statement="com.cy.pj.goods.dao.GoodsDao.deleteById";
        return sqlSession.delete(statement,id);
    }

    @Override
    public int deleteObjects(Integer... ids) {
        String statement="com.cy.pj.goods.dao.GoodsDao.deleteObjects";
        Map<String,Object> map=new HashMap<>();
        map.put("ids", ids);
        return sqlSession.delete(statement,map);
    }
}
